import React, { Component } from 'react'
import queryString from 'query-string'

export default class PathParams extends Component {
  componentDidMount() {
    // 处理方式1
    let params = new URLSearchParams(this.props.location.search);
    // console.log(params.get('id'));
    // console.log(params.get('name'));

    // ======================
    // 处理方式2,需要安装依赖 npm i query-string -S
    let obj = queryString.parse(this.props.location.search);
    console.log(obj);
    // 如果通过state传参
    console.log(this.props.location.state);
  }
  render() {
    console.log(this.props);
    return (
      <div>
        <p>演示如何处理路由参数</p>
      </div>
    )
  }
}
